package regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class OnlyAndBothNumberAndLetters {

    public static void main(final String[] args) {

        String pattern = "(\\d+[a-zA-Z]+|[a-zA-Z]+\\d+)[\\da-zA-Z]*";
        Pattern compile = Pattern.compile(pattern);

        String string = "12345678";
        Matcher matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abcDEFghig";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "1234abDF";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "2b";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abDF1234";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "b2";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "abc123abc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "b2b";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "123abc123";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "2b2";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "123abc123!";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "123abc 123";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));
    }
}
